//
//  WMEClubListViewController.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/2/29.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEClubListViewController.h"
#import "WMEClubListTableViewCell.h"
#import "WMEClubInformationModel.h"
#import <AFNetworking.h>
#import "WMEClubNewsViewController.h"
@interface WMEClubListViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@end

@implementation WMEClubListViewController
- (void)dealloc
{
    [_tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"俱乐部";
    if (_dataArr.count == 0) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"没有数据";
        label.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
        [self.view addSubview:label];
    }else{
        [self createTableView];
    }
}
#pragma mark -创建tableView
- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
}
#pragma mark- tableView的协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WMEClubInformationModel *model = _dataArr[indexPath.row];
    [_tableView registerClass:[WMEClubListTableViewCell class] forCellReuseIdentifier:@"clubListCell"];
    WMEClubListTableViewCell *clubListCell = [_tableView dequeueReusableCellWithIdentifier:@"clubListCell" forIndexPath:indexPath];
    if (_dataArr.count != 0) {
        clubListCell.model = model;
        return clubListCell;
    }
    return 0;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WMEClubInformationModel *model = _dataArr[indexPath.row];
    NSString *temp = @"http://203.80.144.212/napi/club/detail/?include_fields=share_links_2%2Ccheck_in%2Cexperience%2Crelated_ad%2Ctop_member_target%2Ctopic_update&platform_version=4.4.4&device_platform=L36h&screen_width=1080&screen_height=1776&__domain=www.duitang.com&app_version=67&club_id=54aa79f8a3101a0f75731ca7&platform_name=Android&locale=zh&app_code=nayutas";
    NSString *url = [temp stringByReplacingOccurrencesOfString:@"club_id=54aa79f8a3101a0f75731ca7" withString:[NSString stringWithFormat:@"club_id=%@", model.selfId]];
    AFHTTPSessionManager *data = [AFHTTPSessionManager manager];
    [data GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        nil;
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = responseObject[@"data"];
        WMEClubNewsViewController *clubNews = [[WMEClubNewsViewController alloc] init];
        clubNews.clubDic = dic;
        [self.navigationController pushViewController:clubNews animated:YES];

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        nil;
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
